﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace LastfmNet.Models
{
    public class Event : LastfmModelBase, IHasFourImages
    {
        public Event()
        {
            this.Id = 0;
            this.Title = string.Empty;
            this.Artists = new List<string>();
            this.Headliner = string.Empty;
            this.Venue = new Venue();
            this.StartDate = DateTime.MinValue;
            this.Description = string.Empty;
            this.ImageSmall = string.Empty;
            this.ImageMedium = string.Empty;
            this.ImageLarge = string.Empty;
            this.ImageExtraLarge = string.Empty;
            this.Attendance = 0;
            this.Reviews = 0;
            this.Tag = string.Empty;
            this.Url = string.Empty;
            this.Website = string.Empty;
            this.Tickets = new List<Ticket>();
            this.Cancelled = false;
            this.Tags = new List<string>();
        }

        public Event(XmlNode eventNode)
        : this()
        {
            if (eventNode == null) return;
            this.InitializeFromXmlNode(eventNode);
        }

        public override void InitializeFromXmlNode(XmlNode node)
        {
            if (node == null) return;
            this.Id = node.GetChildValue("id").ToInteger();
            this.Title = node.GetChildValue("title");
            this.Artists = node.GetChild("artists").GetChildValuesList("artist");
            this.Headliner = node.GetChild("artists").GetChildValue("headliner");
            this.Venue = new Venue(node.GetChild("venue"));
            this.StartDate = node.GetChildValue("startDate").ToDateTime();
            this.Description = node.GetChildValue("description");
            this.ImageSmall = node.GetChildValueWithSpecialAtrribute("image", "size", "small");
            this.ImageMedium = node.GetChildValueWithSpecialAtrribute("image", "size", "medium");
            this.ImageLarge = node.GetChildValueWithSpecialAtrribute("image", "size", "large");
            this.ImageExtraLarge = node.GetChildValueWithSpecialAtrribute("image", "size", "extralarge");
            this.Attendance = node.GetChildValue("attendance").ToInteger();
            this.Reviews = node.GetChildValue("reviews").ToInteger();
            this.Tag = node.GetChildValue("tag");
            this.Url = node.GetChildValue("url");
            this.Website = node.GetChildValue("website");
            this.Tickets = LastfmModelBase.GetList<Ticket>(node.GetChild("tickets"), "ticket");
            this.Cancelled = node.GetChildValue("cancelled").ToBoolean();
            //TODO:this.Tags
        }

        public int Id { get; set; }

        public string Title { get; set; }

        public IList<string> Artists { get; set; }

        public string Headliner { get; set; }

        public Venue Venue { get; set; }

        public DateTime StartDate { get; set; }

        public string Description { get; set; }

        public string ImageSmall { get; set; }

        public string ImageMedium { get; set; }

        public string ImageLarge { get; set; }

        public string ImageExtraLarge { get; set; }

        public int Attendance { get; set; }

        public int Reviews { get; set; }

        public string Tag { get; set; }

        public string Url { get; set; }

        public string Website { get; set; }

        public IList<Ticket> Tickets { get; set; }

        public bool Cancelled { get; set; }

        public IList<string> Tags { get; set; }
    }
}
